﻿package plugin.viptq
{
    import com.core.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.newvip.model.*;
    import pluginfw.nio.*;
    import uiresource.vipui.*;
    import view.message.*;

    public class ViptqCtrl extends VipUI
    {
        private var _cfgtequan:Object;
        private var vipdata:Object;
        private var useKaId:int = 3;
        private var curKaid:int = 3;

        public function ViptqCtrl()
        {
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            var _loc_1:* = Control.create(ViptqCon, this);
            ModelProxy.addObserver("vip", _loc_1);
            this._cfgtequan = ConfigDictionary.data.tequan;
            this.init();
            this.addEvent();
            return;
        }// end function

        private function addEvent() : void
        {
            closeBtn.addEventListener(MouseEvent.CLICK, this.onclose);
            tongVIP.addEventListener(MouseEvent.CLICK, this.vipka);
            yingVIP.addEventListener(MouseEvent.CLICK, this.vipka);
            jinVIP.addEventListener(MouseEvent.CLICK, this.vipka);
            czBtn.addEventListener(MouseEvent.CLICK, this.buytq);
            return;
        }// end function

        public function init() : void
        {
            this.vipdata = ModelProxy.getValue("vip", "getvip");
            this.initTQ(this.curKaid);
            this.tequanView();
            return;
        }// end function

        public function getVipdata(param1:Object) : void
        {
            this.vipdata = param1;
            this.init();
            return;
        }// end function

        private function initTQ(param1:int) : void
        {
            xianLabel.text = this._cfgtequan[param1].price;
            kuang.y = (3 - param1) * 107 + 118;
            shuomingLabel.text = this._cfgtequan[param1].des;
            return;
        }// end function

        private function tequanView() : void
        {
            var _loc_1:int = 0;
            var _loc_2:Date = null;
            if (this.vipdata == null)
            {
                return;
            }
            if (this.vipdata.privilegeCardLevel > 0)
            {
                time.visible = true;
                time.y = (3 - this.vipdata.privilegeCardLevel) * 107 + 180;
                _loc_1 = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
                _loc_2 = new Date(this.vipdata.privilegeCardEndTime * 1000 - _loc_1 * 1000);
                time.text = "生效时间:" + int(_loc_2.time / 86400000) + "天";
            }
            else
            {
                time.visible = false;
            }
            return;
        }// end function

        protected function buytq(event:MouseEvent) : void
        {
            var event:* = event;
            Alert2.show("是否确认购买特权卡？", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                var _loc_3:Output = null;
                if (param1 == 0)
                {
                    _loc_3 = new Output();
                    _loc_3.writeVarInt(curKaid, false);
                    PluginManager.instance.sendToBufferServer("vip", CMDVip.LingQuFirst, _loc_3);
                }
                return;
            }// end function
            );
            return;
        }// end function

        protected function vipka(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as UrlImage;
            switch(_loc_2)
            {
                case tongVIP:
                {
                    this.curKaid = 1;
                    biaoti.url = "cs2_viproot/huangtong.png";
                    break;
                }
                case yingVIP:
                {
                    this.curKaid = 2;
                    biaoti.url = "cs2_viproot/baiyin.png";
                    break;
                }
                case jinVIP:
                {
                    this.curKaid = 3;
                    biaoti.url = "cs2_viproot/huangjin.png";
                    break;
                }
                default:
                {
                    break;
                }
            }
            this.initTQ(this.curKaid);
            return;
        }// end function

        protected function onclose(event:MouseEvent) : void
        {
            ModelProxy.change("plugin", "close", "viptq");
            return;
        }// end function

    }
}
